package com.cloudOffice.config;

import com.cloudOffice.interceptor.JwtTokenInterceptor;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * SpringMVC配置类
 */
@Slf4j

@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {
	
	@Resource
	private JwtTokenInterceptor jwtTokenInterceptor;
	
	/**
	 * 注册自定义拦截器
	 */
	@Override
	public void addInterceptors(InterceptorRegistry registry) {
		// 排除用户
		registry.addInterceptor(jwtTokenInterceptor)
				.addPathPatterns("/admin/**")
				.excludePathPatterns("/admin/system/index/login", "/admin/system/index/ceshi");
	}
	
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		// 配置静态资源
		registry.addResourceHandler("/**").addResourceLocations("classpath:/static/");
		// 配置knife4j 显示文档
		registry.addResourceHandler("/doc.html")
				.addResourceLocations("classpath:/META-INF/resources/");
		// 配置swagger-ui显示文档
		registry.addResourceHandler("/swagger-ui/**")
				.addResourceLocations("classpath:/META-INF/resources/");
		// 公共部分内容
		registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
	}
}
